/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Presentacion;

import java.awt.*;
import java.awt.event.*;
import java.sql.SQLException;
import javax.swing.*;
import javax.swing.border.*;
import java.util.Calendar;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.freixas.jcalendar.*;



/**
 *
 * @author debo
 */
public class Calendario extends javax.swing.JDialog {
    AltaOrden altaOrden;
    OrdenesPendientes pendientes=null;
    JCalendar calendar; 
    String date;
    Calendario calendario =  null;
    
    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }
    /**
     * Creates new form Calendario
     */
    public Calendario(java.awt.Frame parent, boolean modal) throws SQLException {
        super(parent, modal);
        initComponents();
         setTitle("    Calendario ");
          
               MyDateListener listener = new MyDateListener();
         Border etchedBorder =
	BorderFactory.createEtchedBorder();
    Border emptyBorder =
	BorderFactory.createEmptyBorder(10, 10, 10, 10);
    Border compoundBorder =
	BorderFactory.createCompoundBorder(etchedBorder, emptyBorder);

    JCalendarCombo calendar1 =
	new JCalendarCombo(
	    JCalendarCombo.DISPLAY_DATE | JCalendarCombo.DISPLAY_TIME,
	    true);
         

    calendar1.setEditable(true);
    calendar1.addDateListener(listener);

    // Set fonts rather than using defaults

    calendar1.setFont(new Font("DialogInput", Font.PLAIN, 16));

    calendar1.setTitleFont(new Font("Serif", Font.BOLD|Font.ITALIC, 24));
    calendar1.setDayOfWeekFont(new Font("SansSerif", Font.ITALIC, 12));
    calendar1.setDayFont(new Font("SansSerif", Font.BOLD, 16));
    calendar1.setTimeFont(new Font("DialogInput", Font.PLAIN, 10));
    calendar1.setTodayFont(new Font("Dialog", Font.PLAIN, 14));

    calendar1.addDateListener(listener);
    calendar1.setBorder(compoundBorder);

         //    setDefaultCloseOperation(EXIT_ON_CLOSE);

//    Container contentPane = getContentPane();
//    contentPane.setLayout(new GridLayout(2, 2, 5, 5));
//
//    // Create a border for all calendars
//
//    Border etchedBorder =
//	BorderFactory.createEtchedBorder();
//    Border emptyBorder =
//	BorderFactory.createEmptyBorder(10, 10, 10, 10);
//    Border compoundBorder =
//	BorderFactory.createCompoundBorder(etchedBorder, emptyBorder);

    // Create a date listener to be used for all calendars

   

    // Display date and time using the default calendar and locale.
    // Display today's date at the bottom.

//    JCalendar calendar1 =
//	new JCalendar(
//	    JCalendar.DISPLAY_DATE | JCalendar.DISPLAY_TIME,
//	    true);
//    calendar1.addDateListener(listener);
//    calendar1.setBorder(compoundBorder);
//
//    // Set fonts rather than using defaults
//
//    calendar1.setTitleFont(new Font("Serif", Font.BOLD|Font.ITALIC, 24));
//    calendar1.setDayOfWeekFont(new Font("SansSerif", Font.ITALIC, 12));
//    calendar1.setDayFont(new Font("SansSerif", Font.BOLD, 16));
//    calendar1.setTimeFont(new Font("DialogInput", Font.PLAIN, 10));
//    calendar1.setTodayFont(new Font("Dialog", Font.PLAIN, 14));

    // Display date only

//    JCalendar calendar2 = new JCalendar(JCalendar.DISPLAY_DATE, false);
//    calendar2.addDateListener(listener);
//    calendar2.setBorder(compoundBorder);
//
//    // Display time only and set the time pattern to use as a duration
//    // from 00:00 to 23:59
//
//    JCalendar calendar3 =
//	new JCalendar(
//	    Calendar.getInstance(),
//	    Locale.getDefault(),
//	    JCalendar.DISPLAY_TIME,
//	    false,
//	    "HH:mm");
//    calendar3.addDateListener(listener);
//    calendar3.setBorder(compoundBorder);
//
//    // Display a French calendar
//
//    JCalendar calendar4 =
//	new JCalendar(
//	    Calendar.getInstance(Locale.FRENCH),
//	    Locale.FRENCH,
//	    JCalendar.DISPLAY_DATE | JCalendar.DISPLAY_TIME,
//	    false);
//    calendar4.addDateListener(listener);
//    calendar4.setBorder(compoundBorder);
//
//    // Add all the calendars to the content pane

//    JPanel panel1 = new JPanel(new FlowLayout());
//    panel1.add(calendar1);
//    contentPane.add(panel1);

//    JPanel panel2 = new JPanel(new FlowLayout());
//    panel2.add(calendar2);
//    contentPane.add(panel2);
//
//    JPanel panel3 = new JPanel(new FlowLayout());
//    panel3.add(calendar3);
//    contentPane.add(panel3);
//
//    JPanel panel4 = new JPanel(new FlowLayout());
//    panel4.add(calendar4);
//    contentPane.add(panel4);

    // Make the window visible

    pack();
    //setVisible(true);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jCalendar1 = new org.freixas.jcalendar.JCalendar();
        jButton1 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jCalendar1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jCalendar1MouseClicked(evt);
            }
        });
        jCalendar1.addDateListener(new org.freixas.jcalendar.DateListener() {
            public void dateChanged(org.freixas.jcalendar.DateEvent evt) {
                jCalendar1DateChanged(evt);
            }
        });

        jButton1.setText("Cerrar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel1.setText("Fecha");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addComponent(jCalendar1, javax.swing.GroupLayout.PREFERRED_SIZE, 480, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 21, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(44, 44, 44)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton1)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jCalendar1, javax.swing.GroupLayout.DEFAULT_SIZE, 241, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(35, 35, 35)
                        .addComponent(jButton1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jCalendar1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jCalendar1MouseClicked
        
         
    }//GEN-LAST:event_jCalendar1MouseClicked

    private void jCalendar1DateChanged(org.freixas.jcalendar.DateEvent evt) {//GEN-FIRST:event_jCalendar1DateChanged
               Calendar c ;
             
//         MyDateListener listener = new MyDateListener();
         // c= evt.getSelectedDate();
          
               c = evt.getSelectedDate();
               date=c.getTime().toString();
              jTextField1.setText(date.toString());  
    try {
        pendientes = new OrdenesPendientes(null, rootPaneCheckingEnabled);
    } catch (SQLException ex) {
        Logger.getLogger(Calendario.class.getName()).log(Level.SEVERE, null, ex);
    }
               pendientes.setVisible(true);
         
//               if (c != null) {
////        OrdenesPendientes pendientes = new OrdenesPendientes(null, rootPaneCheckingEnabled);
////        pendientes.setVisible(true);
//        System.out.println(c.getTime());
//        
//    }
//    else {
//	System.out.println("No time selected.");
//    }

          //DateEvent e = new DateEvent(evt, Calendar.getInstance());
          
               
    }//GEN-LAST:event_jCalendar1DateChanged

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Calendario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Calendario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Calendario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Calendario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                Calendario dialog = null;
                try {
                    dialog = new Calendario(new javax.swing.JFrame(), true);
                } catch (SQLException ex) {
                    Logger.getLogger(Calendario.class.getName()).log(Level.SEVERE, null, ex);
                }
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private org.freixas.jcalendar.JCalendar jCalendar1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables

    private void dateChanged(DateEvent e) {
             //To change body of generated methods, choose Tools | Templates.
    }
 


private class MyDateListener
      implements DateListener
{

        @Override
        public void dateChanged(DateEvent de) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    }
//
//
//    public void dateChanged(DateEvent e)
//   {
//     Calendar c = e.getSelectedDate();
//      if (c != null) {
//        OrdenesPendientes pendientes = new OrdenesPendientes(null, rootPaneCheckingEnabled);
//        pendientes.setVisible(true);
//             
//        System.out.println(c.getTime());
//        
//    }
//    else {
//	System.out.println("No time selected.");
//    }
//}
//
//}
  
}


